home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / masm.arc / ASMUTILS.ASM next >
Assembly Source File  |  1985-03-06  |  13KB  |  458 lines

  1.        PAGE 62,132
  2. ;
  3. ; Assembler Utilities : clear screen
  4. ;                       locate
  5. ;                       clear input buffer
  6. ;                       set attribute byte
  7. ;                       write to screen buffer
  8. ;                       read from screen buffer
  9. ;-----------------------------------------
  10. cseg   segment para public 'code'
  11. ;
  12. ; cls    - subroutine to clear the screen
  13. ;        - called from PASCAL
  14. ;
  15. ;Procedure CLS;         PASCAL statement
  16. ;
  17. ;AUTHOR: Barry Shiffrin
  18. ;
  19.        public cls
  20. cls    proc  far         ;called from pascal
  21.        assume cs:cseg
  22.        push  bp          ;save frame pointer
  23.        mov  bp,sp    ;to address parms
  24. ;
  25.        mov cx,0
  26.        mov dx,184Fh
  27.        mov bh,7
  28.        mov ax,600h
  29.        int 10h
  30. ;
  31. retrun: pop  bp          ;get frame pointer
  32.         ret
  33. cls    endp
  34. page
  35. ;
  36. ; locate - subroutine to locate the cursor
  37. ;        - called from PASCAL
  38. ;
  39. ; Author:Barry Shiffrin
  40. ;
  41. ;Procedure LOCATE (row,col: integer);   PASCAL statement
  42. ;
  43. ;first parameter is 1 origin row
  44. ;second parameter is 1 origin column
  45. ;
  46. ;ex: LOCATE(1,1)   - locates cursor at upper left corner of screen
  47. ;    LOCATE(25,80) - locates cursor at lower right corner of screen
  48. ;
  49. ;The next write after a locate will write the data at the located
  50. ;    cursor position.
  51. ;
  52. ;FRAME:
  53. ;        row     ; 8
  54. ;        col     ; 6
  55. ;     <ret/bp>   ; 0
  56. ;
  57. ;
  58.        public locate
  59. locate proc  far         ;called from pascal
  60. ;
  61.        push  bp          ;save frame pointer
  62.        mov  bp,sp        ;to address parms
  63. ;
  64.        mov dl,[bp+6]
  65.        mov dh,[bp+8]
  66.        dec dh
  67.        dec dl
  68.        mov bh,0
  69.        mov ah,2
  70.        int 10h
  71. ;
  72.        pop  bp          ;get frame pointer
  73.        ret   4          ;return pop 2
  74. locate endp
  75. ;
  76. page
  77. ;clrbuf - routine to clear keyboard buffer
  78. ;       - called from PASCAL
  79. ;
  80. ; Author:Barry Shiffrin
  81. ;
  82. ;Procedure CLRBUF;     PASCAL statement
  83. ;
  84. ;When called, this procedure will clear out the keyboard buffer
  85. ;     removing any keys which the user may have 'typed ahead'
  86. ;
  87. ;
  88.         public clrbuf
  89. clrbuf  proc far
  90. ;
  91.         push bp
  92.         mov bp,sp
  93.         mov dl,0ffh
  94.         mov ah,0ch
  95.         mov al,06h
  96.         int 21h
  97.         pop bp
  98.         ret
  99. clrbuf  endp
  100. page
  101. ;
  102. ;
  103. ; attrib - subroutine to write attribute bytes on the screen
  104. ;        - called from PASCAL
  105. ;
  106. ; Author:Barry Shiffrin
  107. ;
  108. ;Procedure ATTRIB (r,c:integer; at:integer; ct:integer);     PASCAL statement
  109. ;
  110. ;first parameter is 1 origin row
  111. ;second parameter is 1 origin column
  112. ;third parameter is the attribute byte to be written
  113. ;                  (the lower byte of the integer is used)
  114. ;fourth parameter is the number of these attributes to write
  115. ;
  116. ;ex: ATTRIB(1,1,16#70,5); writes attribute 70H starting at 1,1 for 5 bytes
  117. ;
  118. ;
  119. ;FRAME:
  120. ;        r       : 12
  121. ;        c       : 10
  122. ;        at      ; 8
  123. ;        ct      ; 6
  124. ;     <ret/bp>   ; 0
  125. ;
  126. ;
  127. ;
  128.         public attrib
  129. attrib  proc far
  130. ;
  131.         push bp
  132.         mov bp,sp
  133.         push es
  134. ;
  135.         cld
  136.         mov ah,15
  137.         int 10H
  138.         cmp al,7
  139.         jne col
  140.         mov ax,0B000H        ;setup segment for mono card
  141.         jmp l1
  142.     col:mov ax,0B800H        ;setup segment for color card
  143.      l1:mov es,ax
  144. ;
  145.         sub di,di            ;calculate offset into segment
  146.         mov cx,[bp+6]        ;get count
  147.         mov ax,[bp+12]       ;get row
  148.         dec ax               ; make it 0 origin
  149.         mov dx,160
  150.         mul dx               ;perform the multiplication
  151.         mov di,ax            ;store results in di
  152.         mov ax,[bp+10]       ;get column byte
  153.         dec ax               ;make it 0 origin
  154.         shl ax,1             ;perform multiplication
  155.         add di,ax            ;add to previous calculation
  156.         add di,1             ;add 1 to point to attribute byte
  157. ;
  158.         mov al,[bp+8]        ;get attribute byte
  159. ;
  160.     agn:stosb                ;write attribute and inc di by 1
  161.         inc di               ;increment address by 1 more to next attrib
  162.         loop agn
  163. ;
  164.         pop es
  165.         pop bp
  166.         ret 8
  167. attrib  endp
  168. ;
  169. page
  170. ;
  171. ; writeat - subroutine to write attribute bytes and data on the screen
  172. ;        - called from PASCAL
  173. ;
  174. ; Author:Barry Shiffrin
  175. ;
  176. ;Procedure WRITEAT (r,c,at:integer; var sp:lstring);     PASCAL statement
  177. ;    or
  178. ;Procedure WRITEAT (r,c,at:integer; const sp:lstring);     PASCAL statement
  179. ;
  180. ;first parameter is 1 origin row
  181. ;second parameter is 1 origin column
  182. ;third parameter is the attribute byte to be written
  183. ;                  (the lower byte of the integer is used)
  184. ;fourth parameter is the lstring to be written
  185. ;                 the length of this string is passed automatically
  186. ;ex: abc := 'test string';
  187. ;    WRITEAT(1,1,16#70,abc); writes attribute 70H starting at 1,1 for
  188. ;                               10 bytes and also writes the string
  189. ;
  190. ;NOTE:if the second form of the declare is used a constant string may be
  191. ;      included as immediate data.
  192. ;FRAME:
  193. ;        r       : 14
  194. ;        c       : 12
  195. ;        at      : 10
  196. ;        length  : 8      note that this is max length of lstring
  197. ;        sp      : 6
  198. ;     <ret/bp>   ; 0
  199. ;
  200. ;          the actual length of lstring is the first byte of the string
  201. ;
  202.         public writeat
  203. writeat proc far
  204. ;
  205.         push bp
  206.         mov bp,sp
  207.         push es
  208. ;
  209.         cld
  210.         mov ah,15
  211.         int 10H
  212.         cmp al,7
  213.         jne wcol
  214.         mov ax,0B000H        ;setup segment for mono card
  215.         jmp wl1
  216.    wcol:mov ax,0B800H        ;setup segment for color card
  217.     wl1:mov es,ax
  218. ;
  219.         sub di,di            ;calculate offset into segment
  220.         mov bx,[bp+6]        ;get address of string
  221.         sub cx,cx
  222.         mov cl,[bx]          ;get count from first byte of string
  223.         mov ax,[bp+14]       ;get row
  224.         dec ax               ; make it 0 origin
  225.         mov dx,160
  226.         mul dx               ;perform the multiplication
  227.         mov di,ax            ;store results in di
  228.         mov ax,[bp+12]       ;get column byte
  229.         dec ax               ;make it 0 origin
  230.         shl ax,1             ;perform multiplication
  231.         add di,ax            ;add to previous calculation
  232. ;                            ;this now points to character byte
  233.         mov ah,[bp+10]       ;get attribute byte
  234.         mov si,[bp+6]        ;get address of string
  235.         inc si               ;increment past length byte of lstring
  236. ;
  237.         mov al,[si]          ;get character from string
  238.    wagn:stosw                ;write character and attribute-reversed in mem
  239.         inc si               ;increment to next character in string
  240.         mov al,[si]          ;get next character
  241.         loop wagn
  242. ;
  243.         pop es
  244.         pop bp
  245.         ret 10
  246. writeat endp
  247. ;
  248. page
  249. ;
  250. ; readat - subroutine to read data from the screen
  251. ;        - called from PASCAL
  252. ;
  253. ; Author:Barry Shiffrin
  254. ;
  255. ;Procedure READAT (r,c:integer; var sp:string);     PASCAL statement
  256. ;
  257. ;first parameter is 1 origin row
  258. ;second parameter is 1 origin column
  259. ;third parameter is the string into which the data should be placed
  260. ;                 the length of this string is passed automatically
  261. ;    var abc : string(5);
  262. ;    READAT(1,1,abc); reads the 5 bytes starting at 1,1
  263. ;                               and places them into string abc
  264. ;
  265. ;FRAME:
  266. ;        r       : 12
  267. ;        c       : 10
  268. ;        length  : 8
  269. ;        sp      : 6
  270. ;     <ret/bp>   ; 0
  271. ;
  272. ;
  273. ;
  274.         public readat
  275. readat  proc far
  276. ;
  277.         push bp
  278.         mov bp,sp
  279.         push ds
  280.         mov ax,ds
  281.         mov es,ax            ;setup es to point to ds
  282. ;
  283.         cld
  284.         mov ah,15
  285.         int 10H
  286.         cmp al,7
  287.         jne rcol
  288.         mov ax,0B000H        ;setup segment for mono card
  289.         jmp rl1
  290.    rcol:mov ax,0B800H        ;setup segment for color card
  291.     rl1:mov ds,ax
  292. ;
  293.         sub si,si            ;calculate offset into segment
  294.         mov cx,[bp+8]        ;get count
  295.         mov ax,[bp+12]       ;get row
  296.         dec ax               ; make it 0 origin
  297.         mov dx,160
  298.         mul dx               ;perform the multiplication
  299.         mov si,ax            ;store results in di
  300.         mov ax,[bp+10]       ;get column byte
  301.         dec ax               ;make it 0 origin
  302.         shl ax,1             ;perform multiplication
  303.         add si,ax            ;add to previous calculation
  304. ;                            ;this now points to character byte
  305.         mov di,[bp+6]        ;get address of string
  306. ;
  307.    ragn:movsb                ;read character from screen
  308.         inc si               ;increment to next character position
  309.         loop ragn
  310. ;
  311.         pop ds
  312.         pop bp
  313.         ret 8
  314. readat  endp
  315. page
  316. ;
  317. ; mem    - subroutine to find out how much memory is installed
  318. ;        - called from PASCAL
  319. ;
  320. ; Author:Barry Shiffrin
  321. ;
  322. ;Function MEM:word  PASCAL statement
  323. ;
  324. ;
  325. ;
  326. ;
  327.         public mem
  328. mem     proc far
  329.         push  bp          ;save frame pointer
  330.         mov  bp,sp    ;to address parms
  331.         int 12h
  332.         pop bp
  333.         ret
  334. mem     endp
  335. ;
  336. page
  337. ;
  338. ; readatl - subroutine to read data from the screen - returns an lstring
  339. ;           containing data up to the last non-blank field on a line
  340. ;         - called from PASCAL
  341. ;
  342. ; Author:Barry Shiffrin
  343. ;
  344. ;Procedure READATL (r,c,w:integer; var sp:lstring);     PASCAL statement
  345. ;
  346. ;first parameter is 1 origin row
  347. ;second parameter is 1 origin column
  348. ;third parameter is the width of the field to check
  349. ;fourth parameter is the lstring into which the data should be placed
  350. ;    var abc : lstring(5);
  351. ;    READAT(12,23,3,abc); reads the 3 bytes starting at 12,23
  352. ;                               and places them into lstring abc
  353. ;    if the 3 characters were 'a b' then returns 'a b'
  354. ;    if the 3 characters were 'ab ' then returns lstring 'ab'
  355. ;
  356. ;
  357. ;FRAME:
  358. ;        r       : 14
  359. ;        c       : 12
  360. ;        w       : 10
  361. ;        length  : 8
  362. ;        sp      : 6
  363. ;     <ret/bp>   ; 0
  364. ;
  365. ;
  366. ;
  367.         public readatl
  368. readatl proc far
  369. ;
  370.         push bp
  371.         mov bp,sp
  372.         push ds
  373.         mov ax,ds
  374.         mov es,ax            ;setup es to point to ds
  375. ;
  376.         std
  377.         mov ah,15
  378.         int 10H
  379.         cmp al,7
  380.         jne rlcol
  381.         mov ax,0B000H        ;setup segment for mono card
  382.         jmp rll1
  383.   rlcol:mov ax,0B800H        ;setup segment for color card
  384.    rll1:mov ds,ax
  385. ;
  386.         sub si,si            ;calculate offset into segment
  387.         mov cx,[bp+10]       ;get count
  388.         mov ax,[bp+14]       ;get row
  389.         dec ax               ; make it 0 origin
  390.         mov dx,160
  391.         mul dx               ;perform the multiplication
  392.         mov si,ax            ;store results in di
  393.         mov ax,[bp+12]       ;get column byte
  394.         dec ax               ;make it 0 origin
  395.         shl ax,1             ;perform multiplication
  396.         add si,ax            ;add to previous calculation
  397. ;                            ;this now points to character byte
  398.         sub si,2
  399.         shl cx,1             ;multiply cx by 2
  400.         add si,cx            ;point to end of string
  401.         shr cx,1             ;restore count
  402.         mov di,[bp+6]        ;points to lstring length
  403.         push di              ;save for later
  404.         add di,[bp+10]       ;point to last character of lstring
  405.         push di              ;save for later
  406.         mov ah,[bp+8]        ;get max length of lstring
  407.         mov al,[bp+10]       ;get width of read
  408.         cmp ah,al            ;compare max length to request
  409.         jge rlgo             ;jump if ok
  410.         pop di
  411.         pop di
  412.         jmp rldn
  413. ;
  414.    rlgo:movsb                ;move character
  415.         dec si               ;point to next character
  416.         loop rlgo            ;loop until done
  417. ;
  418.         mov cx,[bp+10]       ;restore count
  419.         pop di               ;restore pointer to end of string
  420.      l3:cmp es:byte ptr[di],20H ; compare to a blank
  421.         jne l2
  422.         dec di
  423.         loop l3
  424.      l2:pop di
  425.         mov es:[di],cl        ;set string length
  426. ;
  427. ;
  428.    rldn:cld
  429.         pop ds
  430.         pop bp
  431.         ret 10
  432. readatl endp
  433. ;
  434. page
  435. ;
  436. ; prtstat - subroutine to check printer status - returns non-zero if
  437. ;           printer not available
  438. ;         - called from PASCAL
  439. ;
  440. ; Function PRTSTAT : Byte
  441. ;
  442.         public prtstat
  443. prtstat proc far
  444. ;
  445.         push bp
  446.         mov bp,sp
  447.         mov ax,0200H
  448.         xor dx,dx
  449.         int 17H
  450.         mov al,ah
  451.         xor ah,ah
  452.         xor al,90H            ;flip selected and busy bits
  453.         pop bp
  454.         ret
  455. PRTSTAT endp
  456. cseg    ends
  457.         end
  458.